package cn.lyjuan.android.demofive.ui.groupheader;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.lyjuan.android.demofive.R;
import cn.lyjuan.android.mylibrary.view.sectionlist.PinnedHeaderListView;
import cn.lyjuan.android.mylibrary.view.sectionlist.SectionedBaseAdapter;

/**
 * Created by chad on 2016/6/7.
 */
public class GroupHeaderActivity extends Activity
{
    private PinnedHeaderListView listView;
    private SectionAdapter adp;

    private LayoutInflater lf;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.ui_groupheader);

        initView();

        initDate();
    }

    private void initDate()
    {
        adp = new SectionAdapter();
        listView.setAdapter(adp);
    }

    private void initView()
    {
        listView = (PinnedHeaderListView) this.findViewById(R.id.ui_groupheader);
        lf = LayoutInflater.from(this);
    }

    public static class SectionAdapter extends SectionedBaseAdapter
    {
        @Override
        public Object getItem(int section, int position)
        {
            return null;
        }

        @Override
        public long getItemId(int section, int position)
        {
            return 0;
        }

        @Override
        public int getSectionCount()
        {
            return 2;
        }

        @Override
        public int getCountForSection(int section)
        {
            return 22;
        }

        @Override
        public View getItemView(int section, int position, View convertView, ViewGroup parent)
        {
            LinearLayout ll = null;

            if (null == convertView)
            {
                LayoutInflater lf = LayoutInflater.from(parent.getContext());
                ll = (LinearLayout) lf.inflate(R.layout.ui_groupheader_item, null);
            } else
                ll = (LinearLayout) convertView;

            ((TextView) ll.findViewById(R.id.ui_groupheader_item_text)).setText("Section "+ section + " Item " + position);

            return ll;
        }

        @Override
        public View getSectionHeaderView(int section, View convertView, ViewGroup parent)
        {
            LinearLayout ll = null;
            if (null == convertView)
            {
                LayoutInflater lf = LayoutInflater.from(parent.getContext());
                ll = (LinearLayout) lf.inflate(R.layout.ui_groupheader_header, null);
            } else
                ll = (LinearLayout) convertView;

            ((TextView) ll.findViewById(R.id.ui_groupheader_header_text)).setText("Section " + section);

            return ll;
        }
    }
}